//
//  NSString+stampToStr.m
//  GIFShow
//
//  Created by 陈凯 on 15/6/1.
//  Copyright (c) 2015年 CK. All rights reserved.
//

#import "NSString+stampToStr.h"

@implementation NSString (stampToStr)

+(NSString *)translateTimestamp:(float)stamp{
    NSTimeZone * systemTimeZone = [NSTimeZone systemTimeZone];
    NSTimeInterval interval = [systemTimeZone secondsFromGMT];
    NSDate * date = [[NSDate dateWithTimeIntervalSince1970:stamp] dateByAddingTimeInterval:interval];

    NSDate * nowDate = [[NSDate date]dateByAddingTimeInterval:interval];
    NSString * dateStr = [nowDate.description substringToIndex:10];
    NSDateFormatter * formater = [[NSDateFormatter alloc]init];
    [formater setDateFormat:@"yyyy-MM-dd HH:mm:SS"];
    NSString * dateNowStr = [NSString stringWithFormat:@"%@ 00:00:00",dateStr];
    
    NSDate * dateNow = [formater dateFromString:dateNowStr];
    dateNow = [dateNow dateByAddingTimeInterval:interval];
    
    float timeInterval = [date timeIntervalSinceDate:dateNow];
    if (timeInterval > 0) {
        NSString * nowStr = [date.description substringToIndex:16];
        NSString * returnDateStr = [nowStr substringFromIndex:10];
        return [NSString stringWithFormat:@"今天：%@",returnDateStr];
    }else{
        NSString * returnDateStr = [date.description substringToIndex:16];
        
        return [NSString stringWithFormat:@"发布：%@",returnDateStr];
    }
    return nil;
}

@end
